﻿using PhotoKiosk.Model;
using PhotoKiosk.ViewModel.Helpers;
using System;
using System.Windows.Input;

namespace PhotoKiosk.ViewModel
{
    public class PhotoSectionViewModel : ViewModelBase
    {
        public event ClickHandler _ClickHandler;
        public delegate void ClickHandler();
        private DelegateCommand _IncreaseNumberOfCopiesCommand;
        private DelegateCommand _DecreaseNumberOfCopiesCommand;
        public Photo Photo;

        public PhotoSectionViewModel(Photo i_Photo)
        {
            Photo = i_Photo;
        }

        public int NumberOfCopies
        {
            get
            {
                return Photo.NumberOfCopies;
            }
            set
            {
                Photo.NumberOfCopies = value;
                OnPropertyChanged("IsSelected");
                OnPropertyChanged("NumberOfCopies");
                if (_ClickHandler != null)
                {
                    _ClickHandler();
                }
            }
        }

        public bool IsSelected
        {
            get
            {
                return (Photo.NumberOfCopies != 0);
            }
        }


        public string PhotoPath
        {
            get
            {
                return Photo.FilePath;
            }
            set
            {
                OnPropertyChanged("PhotoPath");
            }
        }

        public string FileName
        {
            get
            {
                return Photo.FileName;
            }
            set
            {
                OnPropertyChanged("FileName");
            }
        }

        public ICommand IncreaseNumberOfCopiesCommand
        {
            get
            {
                if (_IncreaseNumberOfCopiesCommand == null)
                {
                    _IncreaseNumberOfCopiesCommand = new DelegateCommand(param => this.increaseNumberOfCopiesCommandExecute());
                }
                return _IncreaseNumberOfCopiesCommand;
            }

        }

        private void increaseNumberOfCopiesCommandExecute()
        {
            NumberOfCopies++;
        }

        public ICommand DecreaseNumberOfCopiesCommand
        {
            get
            {
                if (_DecreaseNumberOfCopiesCommand == null)
                {
                    _DecreaseNumberOfCopiesCommand = new DelegateCommand(param => this.DecreaseNumberOfCopiesCommandExecute(), param => DecreaseNumberOfCopiesCommandCanExecute());
                }
                return _DecreaseNumberOfCopiesCommand;
            }

        }

        private bool DecreaseNumberOfCopiesCommandCanExecute()
        {
            return (Photo.NumberOfCopies > 0);
        }

        private void DecreaseNumberOfCopiesCommandExecute()
        {
            NumberOfCopies--;
        }
    }
}
